
//===============合同附件==============================
var dataFiles = [];
var tableIdContractFile = "bootstrap-table-file";
var  optionsContractFile= {
    data:dataFiles,
    id:tableIdContractFile,
    toolbar:"toolbar2",
   // url: modelType=="edit"?ctx + "contract/contractFile/list?contractId="+contractId:'',
    createUrl: ctx + "contract/contractFile/add",
    removeUrl: ctx + "contract/contractFile/remove",
    showSearch: false,
    showRefresh: false,
    showColumns: false,
    showToggle: false,
    uniqueId: "contractFileId",
    onEditableSave: onEditableSave,
    modalName: "合同附件",
    columns: [{
        checkbox: true
    },
        {
            field: 'contractFileId',
            title: '合同附件ID',
            visible: false
        },
        {
            field: 'contractId',
            title: '合同ID',
            visible: false,
        },
        {
            field: 'contractFileName',
            title: '附件名称',
        },
        {
            field: 'path',
            title: '图片',
            formatter: function(value, row, index) {
                return $.table.imageView(value,1200,800);
            }
        },
        {
            field: 'type',
            title: '类型',
            formatter: function(value, row, index) {
                return $.table.selectDictLabel(typeDatas, value);
            }
        },
        {
            field: 'suffix',
            title: '附件后缀类型',
            formatter: function(value, row, index) {
                return $.table.selectDictLabel(suffixDatas, value);
            }
        },
        {
            field: 'remark',
            title: '备注'
        }]
};

$(function() {
    if(modelType=="edit"){//编辑
        $.ajax({
            type: "POST",
            url: ctx + "contract/contractFile/list?contractId="+contractId,
            success: function(data) {
                if(data.code==0){
                    dataFiles = data.rows;
                    optionsContractFile.data = dataFiles;
                    $.table.init(optionsContractFile);
                }else{
                    $.modal.alertWarning(data.msg);
                }

            }
        });
    }else{
        $.table.init(optionsContractFile);
    }
});


function onEditableSave (field, row, rowIndex, oldValue, $el) {
    //alert("字段名：" + field + "，当前值：" + row[field]  + "，旧值：" + oldValue);
}
//合同附件
function addContractFile() {
    table.set(tableIdContractFile);
    var url=ctx + "contract/contractFile/add";
    $.modal.open("添加销售合同附件",url,1200,($(window).height() - 50),function (index, layero) {
        var iframeWin =$.modal.getChildFrame(index);// layero.find('iframe')[0];
        // var data =iframeWin.find("#form-contractFile-add").serialize();
        dataFiles.push({
            contractFileId: '',
            contractId: '',
            contractFileName: iframeWin.find("input[name='contractFileName']").val(),
            path: iframeWin.find("input[name='path']").val(),
            type: iframeWin.find("select[name='type']").val()||0,
            suffix: iframeWin.find("select[name='suffix']").val()||0,
            remark: iframeWin.find("input[name='remark']").val()
        }) ;
          optionsContractFile.data=dataFiles;
          $.table.destroy(tableIdContractFile);
          $.table.init(optionsContractFile);
          $.modal.close(index);
    });
}

/* 删除指定表格行 */
function removeRow(){
    var ids = $.table.selectColumns("contractFileId");
    if (ids.length == 0) {
        $.modal.alertWarning("请至少选择一条记录");
        return;
    }
    $("#"+tableIdContractFile).bootstrapTable('remove', {
        field: 'contractFileId',
        values: ids
    })
}

function getAllContractFileData(){
    var data = $("#" + tableIdContractFile).bootstrapTable('getData');
   // alert(JSON.stringify(data))
    return JSON.stringify(data);
}

//===============end 合同附件==============================
